<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div{
            width: 100px;
            height: 100px;
            line-height: 100px;
            text-align: center;
            background-color: rgb(2, 109, 250);
            border-radius: 50%;
            position: fixed;
            bottom: 20px;
            right: 20px;
            display: none;
        }
        body{

            height: 2000px;

        }
    </style>
</head>
<body>
    <div>
        顶部直达
    </div>
    <script>

        var div = document.getElementsByTagName("div")[0]

        // 浏览器发生滚动事件

        window.onscroll = function(){

            var top = document.documentElement.scrollTop || document.body.scrollTop

            console.log(top)

            if(top > 700){

                div.style.display="block"

            }else{

                div.style.display="none"
            }
            div.onclick=function(){
                
                document.documentElement.scrollTop = 0

                document.body.scrollTop = 0
            }
        }

    </script>
</body>
</html>